package com.ellfors.common.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.ellfors.common.app.MyApp
import com.ellfors.common.ext.injectRouter
import com.ellfors.common.utils.TaskManager.addTask
import com.ellfors.common.utils.TaskManager.removeTask
import com.ellfors.common.widget.DeveloperFloatView

/**
 * 不要直接继承这个类
 * 使用[BaseActivity]和[BaseComposeActivity]
 */
sealed class BaseAndroidActivity : AppCompatActivity(), BaseTitleBarOptions {

    private val mDeveloperView by lazy {
        DeveloperFloatView(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //Activity入栈
        this.addTask()
        //注册ARouter
        injectRouter()
    }

    override fun onDestroy() {
        super.onDestroy()
        //Activity出栈
        this.removeTask()
        //隐藏DeveloperView
        if (MyApp.isDebug) {
            mDeveloperView.destroy()
        }
    }

    abstract fun initData()

    fun showDeveloperView() {
        if (MyApp.isDebug) {
            mDeveloperView.show()
        }
    }

    fun hideDeveloperView() {
        if (MyApp.isDebug) {
            mDeveloperView.hide()
        }
    }
}